package com.metrics.utils;

import java.math.*;
import java.text.*;

public class FormatNumberUtil {

	public static Double formatToTwoDecimals(Double number) {
		return formatToDecimals(number, 2);
	}

	public static Double formatToFourDecimals(Double number) {
		return formatToDecimals(number, 4);
	}

	public static double formatToDecimals(double number, int decimals) {
		BigDecimal decimal = new BigDecimal("" + number);
		decimal = decimal.setScale(decimals, BigDecimal.ROUND_HALF_UP);
		return decimal.doubleValue();
	}

	public static String formatTextToFourDecimals(Double number) {
		NumberFormat formatter = new DecimalFormat("#0.0000");
		formatter.setRoundingMode(RoundingMode.HALF_UP);
		String formattedNumber = formatter.format(number);
		return formattedNumber.replace(",", ".");
	}

}